<?
/*
1.撤改只能由供应商操作
2.分销商能查看，但不能操作
*/
include("/var/www/html/new/d/common/header.html");
include("/var/www/html/new/d/common/left.html");
include("/var/www/html/new/d/common/page.php");
include("/var/www/html/new/oop/terminal_change_front.php");

$memberID=$_SESSION['sid'];
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$offset=($currentPage-1)*$pageSize;
$r=array(); 

$dstatusT=array(
    0=>"未操作",
    1=>"<font color='green'>成功</font>",
    2=>"<font color='red'>拒绝</font>"
);

$stypeT=array(
    0=>"修改",
    1=>"撤销"
);

$where="where 1=1 and t.fxid=$memberID";
if($ltitle=$_REQUEST['ltitle']) $where.=" and l.title like '%$ltitle%'";

// 找出自己已受理撤改的（分销商查看）
$union="select t.*,l.title as ltitle,l.apply_did from uu_order_terminal_change t join uu_land l on l.id=t.lid $where";//order by dstatus,stime desc limit $offset,$pageSize
$union_c="select count(*) as total from uu_order_terminal_change t join uu_land l on l.id=t.lid $where";

if($_SESSION['sdtype']==0){ // 供应商查看
    $sql="SELECT salerid FROM uu_land WHERE apply_did=$memberID AND status<3";
    if($ltitle=$_REQUEST['ltitle']) $sql.=" AND title LIKE '%$ltitle%'"; // 按景区搜索
    $GLOBALS['le']->query($sql);
    $salerids = array();
    while($row=$GLOBALS['le']->fetch_assoc()){
        $salerids[] = $row['salerid'];
    }
    $salerids = implode(',',$salerids);
    if(!$salerids) $salerids=0;
    $str="select t.*,l.title as ltitle,l.apply_did  from uu_order_terminal_change t join uu_land l on l.id=t.lid where t.salerid IN ($salerids) UNION ($union) order by dstatus,stime desc limit $offset,$pageSize";
    
    $count="select count(*) as total  from uu_order_terminal_change where salerid IN ($salerids) UNION ($union_c)";
}elseif($_SESSION['sdtype']==9){// 管理员查看
    $where="where 1=1";
    if($ltitle=$_REQUEST['ltitle']) $where.=" and l.title like '%$ltitle%'";
    
    $str="select t.*,l.title as ltitle,l.apply_did  from uu_order_terminal_change t join uu_land l on l.id=t.lid $where order by stime desc limit $offset,$pageSize ";
    
    $count="select count(*) as total from uu_order_terminal_change t join uu_land l on l.id=t.lid $where";
}

if(!$str) $str=$union;
if(!$count) $count=$union_c;

$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
    $row['action'] = false;
    if($row['apply_did']==$memberID || $_SESSION['sdtype']==9) $row['action'] = true;
	$r[]=$row;
}

$GLOBALS['le']->query($count);
$GLOBALS['le']->fetch_assoc();
$total=$GLOBALS['le']->f("total");
include("tpl/terchange_zax.tpl");
include("common/footer.html")
?>